/**
 * 客户档案管理模块 - Mock基础数据
 * @description 客户相关的静态数据和数据生成器
 * @author CRM开发团队
 * @version 1.0.0
 */

import Mock from 'mockjs'

// ==========================================
// 基础常量数据
// ==========================================

// 客户状态选项
export const CUSTOMER_STATUS = ['有效客户', '潜在客户', '无效客户', '已成交客户', '黑名单'] as const

// 客户状态对应的颜色
export const CUSTOMER_STATUS_COLORS = {
  '有效客户': 'success',
  '潜在客户': 'primary',
  '无效客户': 'info',
  '已成交客户': 'warning',
  '黑名单': 'danger'
} as const

// 健康状态选项
export const HEALTH_STATUS = ['健康良好', '健康一般', '健康较差', '健康很差'] as const

// 健康状态对应的颜色
export const HEALTH_STATUS_COLORS = {
  '健康良好': 'success',
  '健康一般': 'warning',
  '健康较差': 'danger',
  '健康很差': 'danger'
} as const

// 预设标签分类
export const PRESET_TAGS = {
  '价值分类': ['VIP客户', '优质客户', '普通客户', '价格敏感客户'],
  '服务特点': ['易沟通', '需要关怀', '决策慢', '冲动消费'],
  '出行特点': ['喜欢跟团', '偏爱自由行', '只走精品线', '价格敏感'],
  '健康状态': ['身体健康', '需要照顾', '行动不便'],
  '消费习惯': ['多次消费', '首次消费', '犹豫不决', '果断下单']
} as const

// 中文姓名数据
export const SURNAMES = [
  '张', '王', '李', '赵', '刘', '陈', '杨', '黄', '周', '吴', 
  '徐', '孙', '马', '朱', '胡', '郭', '何', '高', '林', '罗',
  '郑', '梁', '谢', '宋', '唐', '许', '韩', '冯', '邓', '曹'
] as const

export const GIVEN_NAMES = {
  male: ['建国', '建华', '建军', '志强', '志明', '国强', '国庆', '德华', '志刚', '建设', '建明', '建平', '建文', '建新', '建伟'],
  female: ['桂花', '桂英', '秀英', '秀花', '美丽', '美玲', '淑芬', '秀梅', '桂珍', '丽华', '淑英', '秀兰', '桂珍', '桂兰', '美珍']
} as const

// 省份城市数据
export const PROVINCES = [
  '北京', '上海', '广东', '江苏', '浙江', '山东', '河南', '四川', 
  '湖北', '湖南', '河北', '辽宁', '黑龙江', '安徽', '福建', '江西',
  '山西', '陕西', '吉林', '重庆', '天津', '云南', '贵州', '甘肃'
] as const

// 职业数据
export const OCCUPATIONS = [
  '工程师', '教师', '医生', '护士', '公务员', '企业管理', '技师', 
  '银行职员', '会计', '司机', '工人', '农民', '服务员', '销售员',
  '保安', '清洁工', '厨师', '维修工', '导购', '营业员'
] as const

// 预算范围选项
export const BUDGET_RANGES = ['经济型', '舒适型', '品质型', '豪华型'] as const

// 预算范围对应的金额区间
export const BUDGET_AMOUNT_MAP = {
  '经济型': { min: 1000, max: 3000 },
  '舒适型': { min: 3000, max: 8000 },
  '品质型': { min: 8000, max: 15000 },
  '豪华型': { min: 15000, max: 30000 }
} as const

// 支付方式选项
export const PAYMENT_METHODS = ['现金支付', '银行转账', '微信支付', '支付宝', '刷卡'] as const

// 国内地域选项
export const DOMESTIC_REGIONS = ['华北', '华东', '华南', '华中', '西南', '西北', '东北', '港澳台'] as const

// 国际地域选项
export const INTERNATIONAL_REGIONS = ['东南亚', '日韩', '欧洲', '澳新', '美洲', '其他'] as const

// 景观偏好选项
export const LANDSCAPE_PREFERENCES = [
  '自然风光', '历史古迹', '海滨度假', '温泉养生', '美食文化', 
  '民俗风情', '都市观光', '摄影采风', '购物娱乐'
] as const

// 气候偏好选项
export const CLIMATE_PREFERENCES = ['温带', '亚热带', '热带', '高原', '避暑', '避寒'] as const

// 季节偏好选项
export const SEASON_PREFERENCES = ['春季', '夏季', '秋季', '冬季'] as const

// 出行天数偏好
export const DURATION_PREFERENCES = ['短途', '中途', '长途', '超长'] as const

// 出行天数对应的天数区间
export const DURATION_DAYS_MAP = {
  '短途': { min: 1, max: 3 },
  '中途': { min: 4, max: 7 },
  '长途': { min: 8, max: 15 },
  '超长': { min: 16, max: 30 }
} as const

// 交通工具选项
export const TRANSPORT_PREFERENCES = ['飞机', '高铁', '普通火车', '大巴车', '自驾车'] as const

// 住宿标准选项
export const ACCOMMODATION_STANDARDS = ['经济型酒店', '舒适型酒店', '高档酒店', '度假村', '民宿客栈'] as const

// 婚姻状况选项
export const MARITAL_STATUS_OPTIONS = ['已婚', '丧偶', '离异', '未婚'] as const

// 行动能力选项
export const MOBILITY_ABILITIES = ['行动自如', '轻微受限', '需要辅助', '轮椅出行'] as const

// 决策模式选项
export const DECISION_PATTERNS = ['自主决策', '咨询决策', '共同决策', '代为决策'] as const

// 影响因素选项
export const INFLUENCE_FACTORS = ['价格因素', '安全因素', '健康因素', '家人意见', '朋友推荐'] as const

// ==========================================
// 数据生成器函数
// ==========================================

/**
 * 生成随机中文姓名
 */
export function generateChineseName(gender?: '男' | '女'): { 
  surname: string
  givenName: string
  fullName: string
} {
  const surname = Mock.Random.pick([...SURNAMES])
  const genderKey = gender === '女' ? 'female' : gender === '男' ? 'male' : Mock.Random.pick(['male', 'female'])
  const givenName = Mock.Random.pick([...GIVEN_NAMES[genderKey as keyof typeof GIVEN_NAMES]])
  
  return {
    surname,
    givenName,
    fullName: surname + givenName
  }
}

/**
 * 生成身份证号
 */
export function generateIdCard(birthYear: number): string {
  const area = '110101' // 北京市东城区
  const month = Mock.Random.integer(1, 12).toString().padStart(2, '0')
  const day = Mock.Random.integer(1, 28).toString().padStart(2, '0')
  const sequence = Mock.Random.string('number', 3)
  const genderCode = Mock.Random.integer(0, 9)
  
  return `${area}${birthYear}${month}${day}${sequence}${genderCode}`
}

/**
 * 生成手机号
 */
export function generatePhoneNumber(): string {
  const prefixes = ['138', '139', '137', '136', '135', '134', '150', '151', '152', '157', '158', '159']
  const prefix = Mock.Random.pick(prefixes)
  const suffix = Mock.Random.string('number', 8)
  return prefix + suffix
}

/**
 * 生成客户标签
 */
export function generateCustomerTags(count: number = 3): Array<{
  id: number
  category: string
  name: string
  isSystem: boolean
  createdAt: string
}> {
  const tags: Array<{
    id: number
    category: string
    name: string
    isSystem: boolean
    createdAt: string
  }> = []
  const categories = Object.keys(PRESET_TAGS) as Array<keyof typeof PRESET_TAGS>
  
  for (let i = 0; i < count && i < categories.length; i++) {
    const category = categories[i] || Mock.Random.pick(categories)
    const tagName = Mock.Random.pick([...PRESET_TAGS[category]])
    
    // 检查是否已存在相同名称的标签
    if (!tags.some(tag => tag.name === tagName)) {
      tags.push({
        id: Mock.Random.increment(),
        category,
        name: tagName,
        isSystem: true,
        createdAt: new Date().toISOString()
      })
    }
  }
  
  return tags
}

/**
 * 生成地址
 */
export function generateAddress(): {
  province: string
  city: string
  district: string
  street: string
  fullAddress: string
} {
  const province = Mock.Random.pick(PROVINCES)
  const city = province + '市'
  const district = Mock.Random.cword(2, 4) + '区'
  const street = Mock.Random.cword(3, 5) + '路' + Mock.Random.integer(1, 999) + '号'
  const fullAddress = city + district + street
  
  return {
    province,
    city,
    district,
    street,
    fullAddress
  }
}

/**
 * 生成旅游偏好数据
 */
export function generateTravelPreferences() {
  const budgetRange = Mock.Random.pick(BUDGET_RANGES)
  const budgetInfo = BUDGET_AMOUNT_MAP[budgetRange]
  
  return {
    budgetRange,
    budgetMin: Mock.Random.integer(budgetInfo.min, budgetInfo.max - 1000),
    budgetMax: Mock.Random.integer(budgetInfo.min + 1000, budgetInfo.max),
    consumptionFeatures: Mock.Random.pick([
      ['价格敏感', '追求性价比'],
      ['注重品质', '预算充足'],
      ['追求性价比']
    ]),
    paymentPreference: Mock.Random.pick(PAYMENT_METHODS),
    domesticRegions: Mock.Random.pick([
      ['华北', '华东'],
      ['华南', '西南'],
      ['华东', '华南', '西南']
    ]),
    internationalRegions: Mock.Random.pick([
      ['东南亚', '日韩'],
      ['欧洲', '澳新'],
      ['东南亚']
    ]),
    landscapePreferences: Mock.Random.pick([
      ['自然风光', '历史古迹'],
      ['海滨度假', '温泉养生'],
      ['自然风光', '民俗风情']
    ]),
    climatePreferences: Mock.Random.pick([
      ['温带', '亚热带'],
      ['亚热带', '热带'],
      ['温带']
    ]),
    seasonPreferences: Mock.Random.pick([
      ['春季', '秋季'],
      ['春季', '冬季'],
      ['夏季', '秋季']
    ]),
    monthPreferences: Mock.Random.pick([
      [3, 4, 5, 9, 10],
      [4, 5, 9, 10, 11],
      [10, 11, 12, 1, 2]
    ]),
    durationPreference: Mock.Random.pick(DURATION_PREFERENCES),
    transportPreferences: Mock.Random.pick([
      ['飞机', '高铁'],
      ['飞机', '大巴车'],
      ['高铁', '大巴车']
    ]),
    accommodationStandard: Mock.Random.pick(ACCOMMODATION_STANDARDS)
  }
}

/**
 * 生成健康信息数据
 */
export function generateHealthInfo() {
  const healthStatus = Mock.Random.pick(HEALTH_STATUS)
  const hasChronicDiseases = Mock.Random.boolean()
  
  return {
    healthStatus,
    mobilityAbility: Mock.Random.pick(MOBILITY_ABILITIES),
    chronicDiseases: hasChronicDiseases ? Mock.Random.pick([
      ['高血压'],
      ['糖尿病'],
      ['高血压', '糖尿病'],
      ['关节炎'],
      []
    ]) : [],
    cardiovascularDiseases: hasChronicDiseases ? Mock.Random.pick([
      [], ['高血压'], ['心脏病'], ['冠心病']
    ]) : [],
    endocrineDiseases: hasChronicDiseases ? Mock.Random.pick([
      [], ['糖尿病'], ['甲状腺疾病']
    ]) : [],
    respiratoryDiseases: Mock.Random.pick([[], ['哮喘'], ['慢阻肺']]),
    musculoskeletalDiseases: Mock.Random.pick([[], ['关节炎'], ['骨质疏松'], ['腰椎疾病']]),
    otherDiseases: Mock.Random.boolean() ? Mock.Random.cword(5, 15) : null,
    medicationInfo: hasChronicDiseases ? Mock.Random.pick([
      '每日服用降压药：厄贝沙坦片1片，早饭后服用',
      '降糖药：二甲双胍0.5g，每日2次',
      '关节炎发作时服用布洛芬缓释胶囊',
      null
    ]) : null,
    dietaryRestrictions: Mock.Random.pick([
      ['无特殊要求'],
      ['低盐低脂'],
      ['糖尿病餐'],
      ['清淡饮食'],
      ['素食']
    ]),
    insuranceInfo: Mock.Random.pick([
      '职工医疗保险，已购买旅游意外险',
      '城镇居民医疗保险',
      '职工医疗保险，每年购买商业医疗险',
      '退休职工医疗保险'
    ])
  }
}

/**
 * 生成家庭信息数据
 */
export function generateFamilyInfo() {
  const maritalStatus = Mock.Random.pick(MARITAL_STATUS_OPTIONS)
  const hasSpouse = maritalStatus === '已婚'
  const hasChildren = Mock.Random.boolean()
  
  return {
    maritalStatus,
    spouseInfo: hasSpouse ? {
      spouseName: generateChineseName().fullName,
      spousePhone: generatePhoneNumber(),
      spouseAge: Mock.Random.integer(55, 75),
      spouseTravelTogether: Mock.Random.pick(['经常同行', '偶尔同行', '从不同行'])
    } : null,
    childrenInfo: hasChildren ? [{
      name: generateChineseName().fullName,
      phone: generatePhoneNumber(),
      relationshipCloseness: Mock.Random.pick(['关系密切', '关系一般', '关系疏远']),
      travelAttitude: Mock.Random.pick(['支持', '中立', '反对'])
    }] : [],
    decisionPattern: Mock.Random.pick(DECISION_PATTERNS),
    influenceFactors: Mock.Random.pick([
      ['价格因素', '安全因素'],
      ['健康因素', '家人意见'],
      ['价格因素', '家人意见'],
      ['安全因素', '朋友推荐']
    ])
  }
}

